import os
import sys
import django
import datetime
import uuid

base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_dir)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "auction.settings")
# 将配置文件的路径写到Django_Settings_Module 环境变量中

django.setup()
# 注意这里导入数据库必须等django启动了才能导入
from api import models
from django.db.models import Sum

deposit_object = models.DepositRecord.objects.filter(item__isnull=True, status=2, user_id=2,
                                                     deposit_type=2, auction_id=1).first()
# 获取订单查看全场保证金是否还拍到了其他单品
order_object = models.Order.objects.filter(status=1, user_id=2,
                                           item__auction=deposit_object.auction).exclude(id=4)
total = 0
for row in order_object:
    total += row.item.deposit
print(total)
print(order_object, deposit_object)
# from utils.encrypt import md5
# import uuid
#
# deposit_object = models.DepositRecord.objects.filter(
#     user_id=2,
#     item_id=34,
#     deposit_type=1
# ).first()
# print(deposit_object.id)
# order_object = models.Order.objects.create(
#             status=1,
#             uid=md5(str(uuid.uuid4())),
#             user_id=2,
#             item_id=34,
#             deposit_id=deposit_object.id,
#             price=1100,
#         )
# print(order_object)
# auction_obj = models.Auction.objects.create(
#     title="看海门票卷",
#     cover="https://wx-1304867879.cos.ap-guangzhou.myqcloud.com/1ccb7469d76d17be.jpg",
#     preview_start_time=current_datetime,
#     preview_end_time=current_datetime + datetime.timedelta(hours=5),
#     auction_start_time=current_datetime + datetime.timedelta(hours=5),
#     auction_end_time=current_datetime + datetime.timedelta(hours=7),
#     deposit=1000,
#     goods_count=0
#
# )
# item_obj = models.AuctionItem.objects.create(
#     auction=auction_obj,
#     uid=str(uuid.uuid4()),
#     title="界钟会动态皮肤号",
#     cover="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp1.itc.cn%2Fq_70%2Fimages03%2F20200622%2F70129c2d3b9146f3b331e8797a7f574f.jpeg&refer=http%3A%2F%2Fp1.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625490546&t=8e38a06cf3dc1d6f2113c7fe73af237b",
#     start_price=350,
#     reserve_price=300,
#     highest_price=600,
#     deposit=150,
#     unit=50,
#
# )
# img_obj = models.AuctionItemImage.objects.create(
#     item=item_obj,
#     img="https://pics1.baidu.com/feed/5366d0160924ab18ef39a5ad2cb63bcb7a890bcb.jpeg?token=e02f50dab87421e1ffaf049fe423da22",
#     carousel=True,
#     order=1
# )
# img_obj2 = models.AuctionItemImage.objects.create(
#     item=item_obj,
#     img="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsinakd20210111ac%2F405%2Fw530h675%2F20210111%2F8217-khmynua3852028.jpg&refer=http%3A%2F%2Fn.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625490766&t=ec9f282badb45627dd708efef786497d",
#     carousel=True,
#     order=2
# )
# img_obj3 = models.AuctionItemImage.objects.create(
#     item=item_obj,
#     img="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%253A%252F%252Fdingyue.ws.126.net%252F2021%252F0428%252F27aa0574p00qs992s00snc000if00grc.png%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625490802&t=a829f0d6a196d952972a264d4c61d61e",
#     carousel=True,
#     order=3
# )
# detail_obj = models.AuctionItemDetail.objects.create(
#     item=item_obj,
#     key="三国杀官方账号",
#     value="界钟会帐号"
# )
#
# item_obj2 = models.AuctionItem.objects.create(
#     auction=auction_obj,
#     uid=str(uuid.uuid4()),
#     title="星甘宁动态皮肤号",
#     cover="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%253A%252F%252Fdingyue.ws.126.net%252F2021%252F0514%252Fad702f3bj00qt2ku9001kc000ku00eqg.jpg%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625490585&t=cf5d34e99e0f87040042830ef24390cc",
#     start_price=300,
#     reserve_price=250,
#     highest_price=400,
#     deposit=150,
#     unit=50,
#
# )
#
# item_obj3 = models.AuctionItem.objects.create(
#     auction=auction_obj,
#     uid=str(uuid.uuid4()),
#     title="界徐盛官方号",
#     cover="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_match%2F0%2F11734519740%2F0.jpg&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625490498&t=3ebeb8dcb2502eb7622ea301e40d15ed",
#     start_price=300,
#     reserve_price=250,
#     highest_price=350,
#     deposit=150,
#     unit=10,
#
# )
